package com.basker.pisces.sequence.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import com.basker.pisces.orm.database.BeanMetaRedisSequenceSynchronizer;
import com.basker.pisces.orm.repository.DefaultRepository;
import com.basker.pisces.redis.sequence.RedisSequenceGenerator;

@Configuration
@ConditionalOnClass({RedisTemplate.class, DefaultRepository.class})
public class RedisSequenceGeneratorConfiguration {

    @Bean
    @ConditionalOnProperty(name = "pisces.sequence.redis.syn.enable", matchIfMissing = true)
    public BeanMetaRedisSequenceSynchronizer beanMetaRedisSequenceSynchronizer() {
        return new BeanMetaRedisSequenceSynchronizer();
    }

    @Bean
    @ConditionalOnProperty(name = "pisces.sequence.source", havingValue = "redis", matchIfMissing = false)
    public RedisSequenceGenerator redisSequenceGenerator() {
        return new RedisSequenceGenerator();
    }
}
